<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ page import="com.conversationboard.model.*" %>
<%@ page import="com.conversationboard.view.*" %>
<%@ page import="com.conversationboard.config.*" %>
<%@ page import="java.security.*" %>
<%@ page import="java.util.List"%>

<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>

<%
	Principal principal = request.getUserPrincipal();
	User user = User.getAnonymousUser();
	
	if (principal != null) {
		user = User.get(principal.getName());
	}
	
	List<Board> boards = Boards.getAuthorisedBoards(user, false);
	request.setAttribute("boards", boards);
	
%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>Search</title>
		<link rel="stylesheet" type="text/css" href="<%=Configuration.getInstance().getRoot()%>/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
		<script src="${contextPath}/Javascript/style.js" type="text/javascript"></script>
	</head>
<body>

	<%= MainMenu.display(principal, Page.SEARCH) %>

	<div class="headingblock">
		<h1>Search</h1>
	</div>

	<div class="mainblock">

		<div class="formattingLink">
			<p><a name="fh" href="#fh" onClick="setStyleByClass('div','formatting','display', 'inline'); setStyleByClass('div','formattingLink','display', 'none');">Show Search Hints</a></p>
		</div>

		<div class="formatting">			
			<h3>Search Hints</h3>

			<p>You can make use of wildcards, such as monkey* to return anything starting with "monkey". You can also make use of boolean
			   logic such as: monkey AND NOT butler, for example, to return items that contain "monkey" but not "butler" (note that the
			   boolean terms must appear in capitals). Place items in quotes to look for phrases, e.g. "monkey butler" to only find items
			   that contain this exact phrase.</p>
			   
			<p>Search terms are not case sensitive. Case sensitivity is only important when using terms such as AND, OR, NOT to indicate
			   boolean logic in the search.</p>
			   
			<p>You can also make use of the fields that are indexed to help you search, so for example, if you want to look for a post you
			   made about Nu Shooz on a given board, you can enter the following in the search field and select the board from the drop-down.</p>
			   
			   <pre>text:"nu shooz" AND loginId:myemailaddress@address.com</pre>
			   
			<p>The fields you can use are: <strong>text</strong> (the body of the post), <strong>title</strong> (the title of a thread),
			   <strong>displayName</strong> (the name you see attached to the thread or post) and <strong>loginId</strong> (your login/email address).</p>
		</div>
				
		<form class="formsection" action="<%=Configuration.getInstance().getRoot()%>/FullTextSearchControllerServlet" method="post">

			<h2>Text Search</h2>

		 	<input name="offset" class="textbox" type="hidden" size="50" value="0" />

		 	<label for="terms">Terms:</label>
			<input name="searchtype" value="text" type="hidden" />
		 	<input name="terms" class="smalltextbox" type="text" size="50" /><br />

		 	Threads Titles: <input name="artefact" type="radio" value="threads" CHECKED /> Posts: <input name="artefact" type="radio" value="messages" />

		 	<p>Leave dates empty if you wish to search the entire database.</p>
		 	<label for="startdate">From: </label><input name="startdate" class="tinytextbox" type="text" size="15" /> <label for="enddate">To: </label><input name="enddate" class="tinytextbox" type="text" size="15" /> (Dates in form: YYYY-MM-DD)
		 	<br />

			<p><strong>Order Results By</strong></p>

		 	<p>Most Relevant First: <input name="sortorder" type="radio" value="Relevance" CHECKED /><br />
		 	Oldest First: <input name="sortorder" type="radio" value="Ascending" /><br />
		 	Newest First: <input name="sortorder" type="radio" value="Descending" /></p>

			<label for="board">Search Board:</label>
			<select name="boardid">
	        	<option value="0">All Boards</option>
	        	<c:forEach var="board" items="${boards}">
	        		<option value="${board.boardId}">${board.name}</option>
	        	</c:forEach>
			</select>

		 	<p><input type="submit" value="       Search      " /></p>
		 	
		</form>

		<form class="formsection" action="<%=Configuration.getInstance().getRoot()%>/FullTextSearchControllerServlet" method="post">
	
			<h2>Search For Threads or Posts Written By a Given User</h2>

		 	<input name="offset" class="textbox" type="hidden" size="50" value="0" />

		 	<p>Login ID (email address): <input name="idtype" type="radio" value="loginid" /><br />
		 	Display Name: <input name="idtype" type="radio" value="displayname" CHECKED /></p>
		 	
			<input name="searchtype" value="id" type="hidden" />

		 	<label for="terms">Login ID (i.e. email address) or Display Name:</label>
		 	<input name="terms" class="smalltextbox" type="text" size="50" /><br />

		 	Threads Titles: <input name="artefact" type="radio" value="threads" CHECKED /> Posts: <input name="artefact" type="radio" value="messages" />
		 	
		 	<p>Leave dates empty if you wish to search the entire database.</p>

		 	<label for="startdate">From: </label><input name="startdate" class="tinytextbox" type="text" size="15" /> <label for="enddate">To: </label><input name="enddate" class="tinytextbox" type="text" size="15" /> (Dates in form: YYYY-MM-DD)
		 	<br />
		
			<p><strong>Order Results By</strong></p>

		 	<p>Most Relevant First: <input name="sortorder" type="radio" value="Relevance" CHECKED /><br />
		 	Oldest First: <input name="sortorder" type="radio" value="Ascending" /><br />
		 	Newest First: <input name="sortorder" type="radio" value="Descending" /></p>

			<label for="board">Search Board:</label>
			<select name="boardid">
	        	<option value="0">All Boards</option>
	        	<c:forEach var="board" items="${boards}">
	        		<option value="${board.boardId}">${board.name}</option>
	        	</c:forEach>
			</select>

		 	<p><input type="submit" value="       Search      " /></p>
		 	
		</form>
		
			
		
		
	</div>
	
	<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
	<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 
	
</body>
</html>
